package cc.idoone.spring_boot_hello.mongodb.bean;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.Date;

/**
 * @author hemj
 * @since 2017/10/20
 */
@Document(collection = "doc_demo")
@CompoundIndex(name = "idx_demo", def = "{'email': 1, 'password': 1, 'locked': 1}")
public class MongoBean implements Serializable {

	@Id
	private String id;
	private String username;
	private String password;
	private String email;
	private boolean locked;
	private Date ts;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean isLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		this.locked = locked;
	}

	public Date getTs() {
		return ts;
	}

	public void setTs(Date ts) {
		this.ts = ts;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		MongoBean mongoBean = (MongoBean) o;

		return id != null ? id.equals(mongoBean.id) : mongoBean.id == null;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder("MongoBean{");
		sb.append("id='").append(id).append('\'');
		sb.append(", username='").append(username).append('\'');
		sb.append(", password='").append(password).append('\'');
		sb.append(", email='").append(email).append('\'');
		sb.append(", locked=").append(locked);
		sb.append(", ts=").append(ts);
		sb.append('}');
		return sb.toString();
	}
}
